1 00:00:00,480 --> 00:00:05,640 Today I'm going to introduce scripting and scripts, run code, which are instructions for our game 2 00:00:05,640 --> 00:00:07,530 so we can make our game do cool stuff. 3 00:00:07,530 --> 00:00:09,420 It adds behavior to the game. 4 00:00:09,570 --> 00:00:15,510 I am on my first game right from the last video and I'm just going to add a block, right? 5 00:00:15,900 --> 00:00:19,890 I'll go here, hit the little arrow block, cool beans. 6 00:00:19,890 --> 00:00:24,930 And then this is part I'm going to rename it to my part. 7 00:00:25,690 --> 00:00:28,380 All right, now we can add a script to my part. 8 00:00:28,390 --> 00:00:29,740 Let's go ahead and do that. 9 00:00:29,770 --> 00:00:34,030 Hit this plus sign right here and you'll have a bunch of stuff that you can add to your part. 10 00:00:34,240 --> 00:00:39,400 Let's type in script so that it limits the list and you can see that there's three different types of 11 00:00:39,400 --> 00:00:42,080 scripts local module and regular. 12 00:00:42,100 --> 00:00:43,240 We'll do all three. 13 00:00:43,270 --> 00:00:45,190 Today we're going to look at this one. 14 00:00:45,220 --> 00:00:48,070 This script right here is a server script. 15 00:00:48,100 --> 00:00:49,840 It just says script. 16 00:00:50,200 --> 00:00:54,040 Let's rename that to print it. 17 00:00:55,240 --> 00:00:55,570 Whoops. 18 00:00:55,570 --> 00:00:58,950 I made my capital T and you can name it whatever you want. 19 00:00:58,960 --> 00:01:00,730 Just have it make sense. 20 00:01:01,330 --> 00:01:01,660 All right. 21 00:01:01,660 --> 00:01:05,900 So we're going to get a print statement that's put here by default. 22 00:01:05,920 --> 00:01:06,360 Right. 23 00:01:06,370 --> 00:01:09,550 And print it opened automatically if you panic. 24 00:01:09,550 --> 00:01:10,120 Oh, my gosh. 25 00:01:10,120 --> 00:01:11,020 Where's my game? 26 00:01:11,020 --> 00:01:12,310 Just go back here. 27 00:01:12,670 --> 00:01:14,020 My first game. 28 00:01:14,020 --> 00:01:14,800 And there it is. 29 00:01:14,800 --> 00:01:17,050 There's your block and there's your little house. 30 00:01:17,050 --> 00:01:18,430 All right, let's go back to print it. 31 00:01:18,430 --> 00:01:19,960 What happens if you close it? 32 00:01:20,380 --> 00:01:21,370 Oh, bummer. 33 00:01:21,400 --> 00:01:22,450 Go back over here. 34 00:01:22,450 --> 00:01:25,030 Double click and it's open again. 35 00:01:25,150 --> 00:01:28,990 If we run this game, we're going to get this message. 36 00:01:28,990 --> 00:01:34,240 In between these speech quotes in the output window, you may be asking, What's the output window? 37 00:01:34,270 --> 00:01:37,000 Go to view output. 38 00:01:37,000 --> 00:01:39,040 There it is, output window. 39 00:01:39,040 --> 00:01:44,530 And you can make this text bigger and smaller by holding the control down and scroll in the mouse button. 40 00:01:45,310 --> 00:01:46,480 All right, let's play it. 41 00:01:46,520 --> 00:01:47,770 Let's see our print out. 42 00:01:47,890 --> 00:01:52,030 So when the block is loaded into the game, the script's going to fire. 43 00:01:52,210 --> 00:01:54,280 All that happen really, really fast. 44 00:01:54,490 --> 00:01:55,810 Hello world. 45 00:01:55,810 --> 00:02:02,230 And you can see it's a server script, it's running on the server and this is the script name and the 46 00:02:02,230 --> 00:02:04,450 line number of that printout. 47 00:02:04,450 --> 00:02:07,390 This is all very handy to know when you're doing troubleshooting. 48 00:02:07,390 --> 00:02:14,830 If you have 100 parts each with 1000 lines of code and you need to know where the error is, I'm going 49 00:02:14,830 --> 00:02:16,210 to show you about that too. 50 00:02:16,210 --> 00:02:18,400 Then this is going to be very helpful. 51 00:02:18,910 --> 00:02:19,870 Let's go to print it. 52 00:02:19,870 --> 00:02:27,160 Let's turn our game off and then let's go ahead and change the message in between these speech quotes. 53 00:02:28,100 --> 00:02:30,470 This is called a string, right? 54 00:02:30,560 --> 00:02:31,780 It's a data type. 55 00:02:31,790 --> 00:02:35,100 It's a string of characters in between speech quotes. 56 00:02:35,120 --> 00:02:42,950 Let's change our message to my custom message and add an exclamation mark, because it's exciting. 57 00:02:42,950 --> 00:02:49,910 Now, when we run it, it's going to say my custom message still on line one, still in print it. 58 00:02:50,600 --> 00:02:51,610 That's cool and all. 59 00:02:51,620 --> 00:02:52,850 Let's add something to it. 60 00:02:53,900 --> 00:02:56,190 Let's go ahead and copy this line of code. 61 00:02:56,210 --> 00:02:59,360 You can do control C or right click copy. 62 00:02:59,370 --> 00:03:03,580 And then I'm going to go down two lines of this blank space. 63 00:03:03,590 --> 00:03:05,570 You can have blank spaces in your code. 64 00:03:05,900 --> 00:03:06,780 That's fine. 65 00:03:06,800 --> 00:03:08,660 And then I just did a paste. 66 00:03:09,050 --> 00:03:13,490 All right, let's make this my second custom message. 67 00:03:15,620 --> 00:03:16,530 And we run it. 68 00:03:16,550 --> 00:03:18,630 We're going to get two messages. 69 00:03:18,650 --> 00:03:22,310 Notice that that blank line did not affect the output. 70 00:03:22,310 --> 00:03:22,730 Right? 71 00:03:22,730 --> 00:03:28,400 The interpreter just skips over those lines and reads out what makes sense and blank lines. 72 00:03:28,400 --> 00:03:31,850 It doesn't read, but it does tell you, hey, we're on line three. 73 00:03:31,850 --> 00:03:37,700 That's kind of cool because let's go ahead and induce an error and see what happens. 74 00:03:38,240 --> 00:03:41,710 I'm going to say error, right? 75 00:03:42,140 --> 00:03:43,100 And nothing by it. 76 00:03:43,130 --> 00:03:45,530 We'll do something weird to like that. 77 00:03:45,980 --> 00:03:46,460 Cool. 78 00:03:46,490 --> 00:03:47,660 See that red line? 79 00:03:47,660 --> 00:03:50,510 That red line saying something's not right. 80 00:03:51,140 --> 00:03:52,160 Let's run our code. 81 00:03:54,710 --> 00:03:58,250 Look at that big old scary red print. 82 00:03:58,250 --> 00:04:00,170 That's never a good thing, is it? 83 00:04:00,200 --> 00:04:04,250 It says incomplete statement, expected assignment or a function call. 84 00:04:04,340 --> 00:04:06,410 And it said, print it, line two. 85 00:04:06,410 --> 00:04:08,090 And here it says line two. 86 00:04:08,630 --> 00:04:09,770 Let's look at line two. 87 00:04:11,300 --> 00:04:11,990 There it is. 88 00:04:12,020 --> 00:04:12,920 There's our error. 89 00:04:12,950 --> 00:04:13,490 Look at that. 90 00:04:13,490 --> 00:04:19,250 Line three didn't even print because this is interpreted by the roadblocks interpreter. 91 00:04:19,370 --> 00:04:21,590 It stopped when it hit an error. 92 00:04:21,620 --> 00:04:23,750 That's important to know when you're doing troubleshooting. 93 00:04:23,750 --> 00:04:27,990 If you don't get to a print statement, you know that something happened prior to that print statement. 94 00:04:28,010 --> 00:04:29,390 Let's fix our error. 95 00:04:31,280 --> 00:04:32,390 And then let's run it. 96 00:04:34,430 --> 00:04:35,520 Everything's good again. 97 00:04:35,540 --> 00:04:36,200 Look at that. 98 00:04:37,230 --> 00:04:38,340 No errors. 99 00:04:38,370 --> 00:04:39,210 Cool. 100 00:04:39,240 --> 00:04:41,310 I'm going to show you one more thing with print statements. 101 00:04:42,570 --> 00:04:49,160 We're going to a print and then I am going to chain together a couple of messages. 102 00:04:49,160 --> 00:04:52,010 So I'm going to say first message. 103 00:04:54,310 --> 00:04:55,390 Comma. 104 00:04:56,650 --> 00:05:01,210 Second message, comma. 105 00:05:01,390 --> 00:05:02,770 Third message. 106 00:05:06,130 --> 00:05:06,820 Look at that. 107 00:05:06,820 --> 00:05:09,600 So you can do multiple things in this print statement. 108 00:05:09,610 --> 00:05:12,520 You can print multiple messages in a print statement. 109 00:05:12,640 --> 00:05:14,200 You just have them comma delimited. 110 00:05:16,070 --> 00:05:17,030 There we go. 111 00:05:17,680 --> 00:05:20,470 Cubans did not print out the commas. 112 00:05:20,470 --> 00:05:20,980 Right. 113 00:05:20,980 --> 00:05:23,380 Just the stuff in between the speech quotes. 114 00:05:24,430 --> 00:05:25,600 Cool beans. 115 00:05:25,630 --> 00:05:27,010 Let's say one more thing. 116 00:05:27,610 --> 00:05:29,410 I'm going to show you what a comment is. 117 00:05:30,800 --> 00:05:31,230 Right. 118 00:05:31,240 --> 00:05:40,390 You do these two dashes and then you can make a comment in your code, something like, I'm not going 119 00:05:40,390 --> 00:05:44,140 to use this script. 120 00:05:44,800 --> 00:05:46,540 It's just for 121 00:05:48,790 --> 00:05:49,990 education. 122 00:05:53,620 --> 00:05:56,230 And that way, maybe put this on the top. 123 00:05:57,250 --> 00:05:59,680 Control X for cut. 124 00:06:02,470 --> 00:06:06,400 Somebody is going through your code and they're like, Oh, what's this printed do? 125 00:06:06,490 --> 00:06:07,900 Then they know right away. 126 00:06:07,900 --> 00:06:10,590 So the comment isn't read by the interpreter. 127 00:06:10,600 --> 00:06:15,520 It is only for programmers, or maybe for you a long time from now where you forget and you're like, 128 00:06:15,520 --> 00:06:16,630 What is this for? 129 00:06:16,660 --> 00:06:19,450 So when we run it, nothing's going to happen. 130 00:06:20,560 --> 00:06:25,480 Now you're probably thinking That's cool and all, but what happens if I'm playing my game and we don't 131 00:06:25,480 --> 00:06:26,860 even really know how to play a game? 132 00:06:26,860 --> 00:06:28,660 I haven't showed you how to do that. 133 00:06:28,660 --> 00:06:32,080 Let's go ahead and save this off file. 134 00:06:33,590 --> 00:06:34,610 Published Road. 135 00:06:37,880 --> 00:06:40,160 Now let's go over to our Web browser. 136 00:06:41,090 --> 00:06:43,960 And we'll go to w w w dot roadblocks dot com. 137 00:06:43,970 --> 00:06:45,590 I'm on the home page. 138 00:06:45,620 --> 00:06:46,810 My home page. 139 00:06:46,820 --> 00:06:48,260 You do that home. 140 00:06:49,870 --> 00:06:51,880 If you're not there, go to create. 141 00:06:51,910 --> 00:06:54,610 Now we hit this tab to download Roadblock Studio. 142 00:06:54,610 --> 00:06:56,490 When we hit that start creating. 143 00:06:56,500 --> 00:07:01,540 Now all we can do is go to manage my experiences and experiences a game. 144 00:07:01,540 --> 00:07:03,160 I don't know why they changed it. 145 00:07:03,550 --> 00:07:04,780 And let's see. 146 00:07:05,650 --> 00:07:07,090 Here's my first game. 147 00:07:07,090 --> 00:07:10,360 I saved that off a second time for something else. 148 00:07:10,360 --> 00:07:14,170 Let's go to my first game and then click right here. 149 00:07:14,170 --> 00:07:17,980 Notice it's private only you can play it my first game. 150 00:07:18,970 --> 00:07:20,200 Cool beans. 151 00:07:20,230 --> 00:07:20,680 All right. 152 00:07:20,680 --> 00:07:25,840 Now, if I hit this big green button, it's going to play my game in the player. 153 00:07:25,840 --> 00:07:28,520 But nobody else can come in because it is private. 154 00:07:28,540 --> 00:07:31,710 I'm going to go ahead and pause this because it takes a second or two to open up. 155 00:07:31,820 --> 00:07:32,590 Oh, no, it doesn't. 156 00:07:32,590 --> 00:07:33,400 It's open. 157 00:07:37,240 --> 00:07:37,800 Cool. 158 00:07:37,810 --> 00:07:38,500 There I am. 159 00:07:38,500 --> 00:07:39,340 But where's my print? 160 00:07:40,000 --> 00:07:41,320 How do I get to them? 161 00:07:42,640 --> 00:07:43,790 We can do two ways. 162 00:07:43,810 --> 00:07:49,120 We can go to this chat box and do a slash console. 163 00:07:49,450 --> 00:07:50,110 Boom. 164 00:07:50,110 --> 00:07:50,640 There it is. 165 00:07:50,650 --> 00:07:51,880 We can make this smaller. 166 00:07:53,030 --> 00:07:53,980 Oh, we can move it. 167 00:07:53,990 --> 00:07:58,070 I held the mouse down while I was dragging that little corner. 168 00:07:58,370 --> 00:08:02,050 And then I'm going to click on here, hold the mouse down and pull it over. 169 00:08:02,060 --> 00:08:05,240 Now this is on client and we have a server script. 170 00:08:05,240 --> 00:08:06,530 So let's go to server. 171 00:08:06,530 --> 00:08:07,460 Look at that. 172 00:08:07,460 --> 00:08:10,010 There's our messages right there. 173 00:08:10,010 --> 00:08:12,020 My, my custom message, my second one. 174 00:08:12,020 --> 00:08:12,980 You get the idea. 175 00:08:13,040 --> 00:08:13,670 Cool. 176 00:08:13,700 --> 00:08:14,870 Another easy way. 177 00:08:14,870 --> 00:08:20,270 If you have a keyboard, let's close this that has the function keys on it. 178 00:08:20,270 --> 00:08:21,710 You could hit F nine. 179 00:08:22,220 --> 00:08:22,790 There we go. 180 00:08:22,790 --> 00:08:23,720 We got it again. 181 00:08:23,720 --> 00:08:24,830 That's pretty cool. 182 00:08:25,010 --> 00:08:30,860 Anyway, that's a little introduction, very simple introduction to scripts, specifically the print 183 00:08:30,860 --> 00:08:31,520 statement. 184 00:08:31,520 --> 00:08:33,590 And I will see you in the next video.